<?php

declare(strict_types=1);

namespace App\Middleware;

use App\Traits\ApiResponseTrait;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class JwtMiddleware implements MiddlewareInterface
{
    use ApiResponseTrait;

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        if (auth('api')->guest())
            return response()->error(401, '请重新登录');

        return $handler->handle($request);
    }

}